package com.xyz.controller;

import com.xyz.aop.Param;
import com.xyz.service.ExternalPostService;
import com.xyz.util.dto.DataResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("externalPost")
public class ExternalPostController {

    private static final Logger logger = LoggerFactory.getLogger(ExternalPostController.class);

    @Autowired
    private ExternalPostService externalPostService;


    @PostMapping("selectEquipment")
    public DataResult selectEquipment(
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize
    ) {
        try {
            return externalPostService.selectEquipment( Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        } catch (Exception e) {
            logger.error("selectEquipment", e);
            return DataResult.build9500();
        }
    }

    /*
    * 线型趋势数据
    * startTime：开始时间
    * endTime：结束时间
    * type: wx(维修趋势曲线图)；wxgz(故障曲线图)
    * */
    @PostMapping("/selectLinearData")
    public DataResult selectLinearData(
            @Param(type = Param.ParamType.DATE, rule = "yyyy-MM-dd") String startTime,
            @Param(type = Param.ParamType.DATE, rule = "yyyy-MM-dd") String endTime,
            @Param String type
    ) {
        try {
            return externalPostService.selectLinearData(startTime,endTime,type);
        } catch (Exception e) {
            logger.error("selectLinearData", e);
            return DataResult.build9500();
        }
    }

    /*
     * 分类汇总
     * startTime：开始时间
     * endTime：结束时间
     * type: sbgzbt（设备故障饼图）；wxph（维修排行）；pjph（人员评价排行）；gdph（人员处理工单数排行）；gsph（人员处理工单工时排行）；bjsy（备件使用排行）
     * */
    @PostMapping("/selectSubtotal")
    public DataResult selectSubtotal(
            @Param(type = Param.ParamType.DATE, rule = "yyyy-MM-dd") String startTime,
            @Param(type = Param.ParamType.DATE, rule = "yyyy-MM-dd") String endTime,
            @Param(isRequired = false, type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param String type
    ) {
        try {
            return externalPostService.selectSubtotal(startTime, endTime, type, pageSize);
        } catch (Exception e) {
            logger.error("selectSubtotal", e);
            return DataResult.build9500();
        }
    }

    /*
     * 获取工单信息
     * startTime：开始时间
     * endTime：结束时间
     * type: wx(维修工单)，wb(维保工单)，xj(巡检工单)
     * */
    @PostMapping("/selectRo")
    public DataResult selectRo(
            @Param(isRequired = false, type = Param.ParamType.DATE, rule = "yyyy-MM-dd") String startTime,
            @Param(isRequired = false, type = Param.ParamType.DATE, rule = "yyyy-MM-dd") String endTime,
            @Param String type
    ) {
        try {
            return externalPostService.selectRo(startTime, endTime, type);
        } catch (Exception e) {
            logger.error("selectRo", e);
            return DataResult.build9500();
        }
    }

    /*
     * 获取维修时间巡检时间维保时间
     * */
    @PostMapping("/selectTimeByEmCode")
    public DataResult selectTimeByEmCode(
            @Param String emCode
    ) {
        try {
            return externalPostService.selectTimeByEmCode(emCode);
        } catch (Exception e) {
            logger.error("selectTimeByEmCode", e);
            return DataResult.build9500();
        }
    }

}
